local jiushi = fk.CreateSkill {
  name = "lingling__jiushi",
}

Fk:loadTranslationTable{
  ["lingling__jiushi"] = "酒诗",
  [":lingling__jiushi"] = "每回合限一次，你可以将两张花色相同的牌当【酒】使用。当你使用【酒】后，你随机获得一张锦囊牌。",

  ["#lingling__jiushi"] = "酒诗：你可以将两张花色相同的牌当【酒】使用",
}

jiushi:addEffect("viewas", {
  pattern = "analeptic",
  prompt = "#lingling__jiushi",
  handly_pile = true,
  card_filter = function(self, player, to_select, selected)
    return #selected < 2 and
      table.every(selected, function (id)
        return Fk:getCardById(id):compareSuitWith(Fk:getCardById(to_select))
      end)
  end,
  view_as = function(self, player, cards)
    if #cards ~= 2 then return end
    local card = Fk:cloneCard("analeptic")
    card:addSubcards(cards)
    card.skillName = jiushi.name
    return card
  end,
  enabled_at_play = function(self, player)
    return player:usedEffectTimes(self.name, Player.HistoryTurn) == 0
  end,
  enabled_at_response = function(self, player, response)
    return not response and player:usedEffectTimes(self.name, Player.HistoryTurn) == 0
  end,
})

jiushi:addEffect(fk.CardUseFinished, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(jiushi.name) and data.card.trueName == "analeptic"
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local cards = room:getCardsFromPileByRule(".|.|.|.|.|trick", 1, "allPiles")
    if #cards > 0 then
      room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, jiushi.name, nil, false, player)
    end
  end,
})

jiushi:addAI(nil, "vs_skill")

return jiushi
